{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 用户输入_文本的格式化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "--------\n",
    "* 时间：2022/10/17 week09"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    ">1. 用户输入\n",
    ">2. 文本的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 1.用户输入\n",
    "> input方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:admin\n",
      "密码:123456\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n"
     ]
    }
   ],
   "source": [
    "print(username)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：mifjif\n",
      "密码：jfijjiji\n",
      "账号不存在或密码不正确！请重新输入！\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1   增加判断\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号：\")\n",
    "password = input(\"密码：\")\n",
    "#情景一：账号密码都正确\n",
    "if user01 == username and password == password:\n",
    "    print(\"登录成功 欢迎\"+user01)\n",
    "#情景二： 账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确！请重新输入！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "2\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "for i in range(3,0,-1):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登录成功，欢迎admin\n",
      "账号：123456\n",
      "密码：123456\n",
      "账号不存在或密码不正确\n",
      "账号：123456\n",
      "密码：13246\n",
      "请一小时后来尝试\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    if user01 == username and  password01 == password:\n",
    "        print(\"登录成功，欢迎\"+user01)\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确\")\n",
    "        else:\n",
    "            print(\"请一小时后来尝试\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* break    #中止循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登录成功，欢迎admin\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    if user01 == username and  password01 == password:\n",
    "        print(\"登录成功，欢迎\"+user01)\n",
    "        break\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确\")\n",
    "        else:\n",
    "            print(\"请一小时后来尝试\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 字符串的格式化输出\n",
    ">1. 字符串的拼接\n",
    ">2. 占位符\n",
    ">3. 格式化输出的方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：广州\n",
      "工作：产品经理\n",
      "年龄：22\n",
      "期待薪资：10k/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）：字符串的拼接\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info ='''---------INFO'''+name+'''--------\n",
    "地区：'''+ region +'''\n",
    "工作：'''+ job +'''\n",
    "年龄：'''+ age +'''\n",
    "薪资期待'''+salary\n",
    "#比较麻烦，容易出错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO李华--------\n",
      "地区：广州\n",
      "工作：产品经理\n",
      "年龄：22\n",
      "薪资期待10k/月\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：广州\n",
      "工作：前端开发\n",
      "年龄：22\n",
      "期待薪资：11k/月\n",
      "---------INFO 李华--------\n",
      "地区：广州\n",
      "工作：前端开发\n",
      "年龄：22\n",
      "薪资期待：11k/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）：占位符%s\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info ='''---------INFO %s--------\n",
    "地区：%s\n",
    "工作：%s\n",
    "年龄：%s\n",
    "薪资期待：%s'''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "#一定的局限性：有序的，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：广州\n",
      "工作：前端开发\n",
      "年龄：22\n",
      "期待薪资：10k/月\n",
      "---------INFO 李华--------\n",
      "地区：广州\n",
      "工作：前端开发\n",
      "年龄：22\n",
      "薪资期待：10k/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）：format()\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info ='''---------INFO {昵称}--------\n",
    "地区：{地区}\n",
    "工作：{工作职位}\n",
    "年龄：{年龄}\n",
    "薪资期待：{薪资}'''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "#  不考虑顺序，只考虑一一对应的关系\n",
    "#  书写规范，字符串中的 字段 一一对应"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课后作业：\n",
    ">1. 第二章p93 前所有项目练习\n",
    ">2. 购物车项目\n",
    ">>要求：\n",
    ">>1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">>2. 让用户输入商品编号进行商品的购买。\n",
    ">>3. 用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    ">>4. 用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
